<?php
/**
用户名：sdk_richzoo
密码：31108272
签名：【Rich众筹】
 */

$sms_lang = array(
    'sign' => '短信签名',

);//该项如果更改通道需要修改
$config = array(
    'sign' => array(
        'INPUT_TYPE' => '0',
        'VALUES' => ''
    )
);
/* 模块的基本信息 */
if (isset($read_modules) && $read_modules == true) {
    $module['class_name'] = 'JIANZHOU';
    /* 名称 */
    $module['name'] = "建周短信通道";
    $module['lang'] = $sms_lang;
    $module['config'] = $config;
    $module['server_url'] = 'http://www.jianzhou.sh.cn/JianzhouSMSWSServer/http';

    return $module;
}

// 建周短信通道
require_once SITE_PATH . "system/libs/sms.php";  //引入接口
require_once SITE_PATH . "system/sms/QXT/transport.php";
require_once SITE_PATH . "system/sms/QXT/XmlBase.php";

class JIANZHOU_sms implements sms
{
    public $sms;
    public $message = "";

    private $statusStr = array(
        "-1" => "余额不足",
        "-2" => "帐号或密码错误",
        "-3" => "连接服务商失败",
        "-4" => "超时",
        "-5" => "其他错误，一般为网络问题，IP受限等",
        "-6" => "短信内容为空",
        "-7" => "目标号码为空",
        "-8" => "用户通道设置不对，需要设置三个通道",
        "-9" => "捕获未知异常",
        "-10" => "超过最大定时时间限制",
        "-11" => "目标号码在黑名单里",
        "-12" => "消息内容包含禁用词语",
        "-13" => "没有权限使用该网关",
        "-14" => "找不到对应的Channel ID",
        "-17" => '没有提交权限，客户端帐号无法使用接口提交',
        "-18" => '提交参数名称不正确或确少参数',
        "-19" => '必须为POST提交',
        "-20" => '超速提交(一般为每秒一次提交)',
    );

    public function __construct($smsInfo = '')
    {
        if (!empty($smsInfo)) {
            $this->sms = $smsInfo;
        }
    }

    public function sendSMS($mobile_number, $content)
    {
        if (is_array($mobile_number)) {
            $mobile_number = implode(";", $mobile_number);
        }
        $url = $this->sms['server_url'].'/sendBatchMessage';

        $sms = new transport();
        //
        $params = array(
            "account" => $this->sms['user_name'],
            "password" => $this->sms['password'],
            "destmobile" => $mobile_number,
            "msgText" => $content.' '.$this->sms['config']['sign'],
        );

        $result = $sms->request($url, $params, 'POST');
        $smsStatus = $result['body'];
        $code = trim($smsStatus);

        if ($code > 0) {
            $result['status'] = 1;
        } else {
            $result['status'] = 0;
            $result['msg'] = isset($this->statusStr[$code]) ? $this->statusStr[$code] : '未知错误';
        }
        return $result;
    }

    public function getSmsInfo()
    {

        return "建周短信通道";

    }

    public function check_fee()
    {
        $sms = new transport();


        $params = array(
            "account" => $this->sms['user_name'],
            "password" => $this->sms['password']
        );
        $url = $this->sms['server_url'].'/getUserInfo';
        $result = $sms->request($url, $params, 'GET');
        $result = toArray($result['body'], "userinfo");
        $str = "建周短信通道，剩余：" . $result['remainFee']['0'] . "条";
        return $str;

    }
}